package com.xfhy.login.service;

import android.app.Activity;

import com.xfhy.componentbase.service.IAccountService;
import com.xfhy.login.data.AccountUtils;
import com.xfhy.login.fragment.UserFragment;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

/**
 * @author : xfhy
 * Create time : 2020-03-01 11:22
 * Description : Login组件中的IAccountService实现类
 */
public class AccountService implements IAccountService {


    @Override
    public boolean isLogin() {
        return AccountUtils.sUserInfo != null;
    }

    @Override
    public String getAccountId() {
        return AccountUtils.sUserInfo == null ? null : AccountUtils.sUserInfo.getAccountId();
    }

    @Override
    public Fragment newUserFragment(Activity activity, int containerId, FragmentManager fragmentManager) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        Fragment userFragment = new UserFragment();
        fragmentTransaction.add(containerId, userFragment);
        fragmentTransaction.commit();
        return userFragment;
    }
}
